package com.huawei.appmarket.service.pay.purchase;

import android.app.Activity;
import android.widget.Toast;
import com.huawei.appgallery.assistantdock.base.externalaction.openviewaction.IOpenViewAction;
import com.huawei.appgallery.productpurchase.api.ProductDetailBean;
import com.huawei.secure.android.common.intent.SafeIntent;
import java.io.Serializable;
import java.lang.ref.WeakReference;
import o.cks;
import o.cku;
import o.crj;
import o.Logger;
import o.ContentManager;
import o.eec;
import o.ewm.n;

public class ProductPurchaseAction extends IOpenViewAction {
    public static final String ACTION = "com.huawei.appmarket.intent.action.buoy.product.purchase";
    public static final String KEY_PRODUCT_BEAN = "product_data";
    private static final String TAG = "ProductPurchaseAction";
    private static a purchaseResultCallback;

    public interface a {
        void ˊ();

        void ˎ();

        void ˏ();

        void ˏ(int i);
    }

    static class b implements crj {
        private ProductDetailBean ˎ;
        private WeakReference<Activity> ॱ;

        public b(Activity activity, ProductDetailBean productDetailBean) {
            this.ˎ = productDetailBean;
            this.ॱ = new WeakReference(activity);
        }

        public void ˎ(int i, ProductDetailBean productDetailBean) {
            switch (i) {
                case 0:
                    if (this.ˎ.ㆍ() == 1) {
                        if (ProductPurchaseAction.purchaseResultCallback != null) {
                            ProductPurchaseAction.purchaseResultCallback.ˎ();
                        }
                        Toast.makeText(ContentManager.getInstant().getContext(), n.ʼꓸ, 0).show();
                    }
                    ˊ();
                    return;
                case 4:
                    if (ProductPurchaseAction.purchaseResultCallback != null) {
                        ProductPurchaseAction.purchaseResultCallback.ˏ(0);
                    }
                    ˏ();
                    return;
                case 5:
                    Toast.makeText(ContentManager.getInstant().getContext(), n.ʼꞌ, 0).show();
                    ˊ();
                    return;
                case 6:
                    if (ProductPurchaseAction.purchaseResultCallback != null) {
                        ProductPurchaseAction.purchaseResultCallback.ˊ();
                    }
                    Toast.makeText(ContentManager.getInstant().getContext(), n.ʼꜞ, 0).show();
                    ˊ();
                    return;
                default:
                    Logger.ˎ(ProductPurchaseAction.TAG, "Purchase failure");
                    ˊ();
                    return;
            }
        }

        private void ˊ() {
            Activity activity = (Activity) this.ॱ.get();
            if (activity != null) {
                activity.finish();
            }
        }

        private void ˏ() {
            Activity activity = (Activity) this.ॱ.get();
            if (activity == null) {
                Logger.ˋ(ProductPurchaseAction.TAG, "handleNoRemain activity null");
                return;
            }
            cku ˏ = cku.ˏ(activity, cku.class, null, activity.getResources().getString(n.ʼᐨ));
            ˏ.ॱ(-1, activity.getResources().getString(n.ʼـ));
            ˏ.ˎ(-2, 8);
            ˏ.ॱ(new cks(this) {
                final /* synthetic */ b ˊ;

                {
                    this.ˊ = r1;
                }

                public void enableNetworking() {
                    if (ProductPurchaseAction.purchaseResultCallback != null) {
                        ProductPurchaseAction.purchaseResultCallback.ˏ();
                    }
                    this.ˊ.ˊ();
                }

                public void upgrade() {
                    this.ˊ.ˊ();
                }

                public void ˋ() {
                    this.ˊ.ˊ();
                }
            });
            ˏ.ˋ(activity, this.ˎ.ॱ());
        }
    }

    public ProductPurchaseAction(o.dys.a aVar, SafeIntent safeIntent) {
        super(aVar, safeIntent);
    }

    public static void registerCallback(a aVar) {
        purchaseResultCallback = aVar;
    }

    public void onAction() {
        if (this.intent != null) {
            Serializable serializableExtra = this.intent.getSerializableExtra(KEY_PRODUCT_BEAN);
            if (serializableExtra instanceof ProductDetailBean) {
                ProductDetailBean productDetailBean = (ProductDetailBean) serializableExtra;
                Activity ˊ = this.callback.ˊ();
                if (ˊ == null) {
                    Logger.ˋ(TAG, "onAction activity null");
                    this.callback.finish();
                    return;
                }
                productDetailBean.ˏ(true);
                eec.ˊ().ˎ(ˊ, productDetailBean, new b(ˊ, productDetailBean));
                return;
            }
            Logger.ˋ(TAG, "onAction data null");
            this.callback.finish();
            return;
        }
        Logger.ˋ(TAG, "onAction intent null");
        this.callback.finish();
    }
}
